<?php
function GetCustomerKeywords(){
	$conn = GetConnection();
	return $conn->query('SELECT * FROM Customer_Keywords');
}

function GetCustomerKeywords_Sorted(){
	$conn = GetConnection();
	return $conn->query('SELECT * FROM Customer_Keywords ORDER BY id DESC');
}

function GetCustomerKeyword($id){
	$conn = GetConnection();
	if($id == null)
		die("No Customer could be found. I.D. invalid.");
	$results = $conn->query("SELECT * FROM Customer_Keywords WHERE id='$id'");
	$row = $results->fetch_assoc();
	$conn->close();
	return $row;
}

function EditCustomerKeyword($row){
	$conn = GetConnection();
	$id = $row['id'];
	$name = strip_tags($row['name']);
	if(strlen($name) > 0)
	{
		$conn->query("UPDATE Customer_Keywords SET name='$name' WHERE id='$id'");
	}
	else
		header("Location: http://cs.newpaltz.edu/~N02432643/%20web-course-2012/final/CustomerKeywords/edit.php?id=".$id."");
	
	$conn->close();
}
function NewCustomerKeyword($row){
	$name = strip_tags($row['name']);
	if(strlen($name) > 0)
	{
		$conn = GetConnection();
		if($conn->query("INSERT INTO Customer_Keywords (id,name) VALUES (NULL,'$name')")){
			$conn->close();
		}
		else{
			die("Query failed");
		}
	}
	else {
			die("You need to enter a Customer Keyword name.");
	}
}

function DeleteCustomerKeyword($id){
		$conn = GetConnection();
		$results = $conn->query("Delete FROM Customer_Keywords WHERE id=$id");
		header('Location: http://cs.newpaltz.edu/~N02432643/%20web-course-2012/final/CustomerKeywords/');
}